package org.ke.factory;
  interface car{
	void run();
	void stop();
	
	}
  class Ford implements car
  {
	  public void run()
	  {
		  System.out.println("ford start");
		  
	  }

	@Override
	public void stop() {
		
		System.out.println("ford stop...");
	}
	  
	  
  }
  class Benz implements car
  {

	@Override
	public void run() {
		System.out.println("benz start...");
		
	}

	@Override
	public void stop() {
		System.out.println("benz stop...");
		
	}
	  
	  
  }
  class Factory
  {
	  public static car getInstance(String type) 
	  {
		 car c = null;
		  
			try {
				c = (car)Class.forName("org.ke.factory."+type).newInstance();
			} catch (InstantiationException e) {
			
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				
				e.printStackTrace();
			}
				  
		return c;  
	  }
  }


public class CarFactoryDemo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		car c = Factory.getInstance("Benz");
		c.run();
		c.stop();

	}

}
